package com.gsoe.problem.controller;

import com.gsoe.base.model.PageResult;
import com.gsoe.base.model.Result;
import com.gsoe.problem.dto.CheckProblemAnswerDTO;
import com.gsoe.problem.dto.ProblemParamDTO;
import com.gsoe.problem.service.ExamRegisterUserService;
import com.gsoe.problem.service.ProblemAnswerService;
import com.gsoe.problem.service.ProblemService;
import com.gsoe.problem.vo.*;

import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 题目表 前端控制器
 * </p>
 *
 * @author xiaoma
 * @since 2024-10-27
 */
@RestController
@RequestMapping("/problem")
public class ProblemController {
    @Autowired
    ProblemService problemService;
    @Autowired
    ProblemAnswerService problemAnswerService;
    @Autowired
    private ExamRegisterUserService examRegisterUserService;

    @PostMapping("/getProblemList")
    public Result<PageResult<ProblemVO>> getProblemList(@RequestBody(required = false) ProblemParamDTO problemParamDTO) {
        return Result.success(problemService.getProblemList(problemParamDTO));
    }
    @PostMapping("/checkProblemAnswer")
    public Result<JudgeVO> checkProblemAnswer(@RequestBody @Valid CheckProblemAnswerDTO problemParamDTO) {
        return Result.success(problemAnswerService.checkProblemAnswer(problemParamDTO.getProblemId(),problemParamDTO.getAnswer()));
    }

    @PostMapping("/getRandomProblem")
    public Result<ProblemRandomVO>getRandomProblem(@RequestBody(required = false)ProblemParamDTO problemParamDTO ) {
         return Result.success(problemService.getRandomProblem(problemParamDTO));
    }

    @GetMapping("/getProblemById/{id}")
    public Result<ProblemVO> getProblemById(@PathVariable Long id) {
        return Result.success(problemService.getProblemById(id));
    }

    @GetMapping("/exam/getUserExamList/{userId}")
    public Result<List<ExamResultVO>> getUserExamList(@PathVariable Long userId){
        return Result.success(examRegisterUserService.getUserExamList(userId));
    }
    /*请求方式:get

     * 请求路径：/problem/getProblemNumberByDiff/{userId}
     * 响应结果: 集合 ,总共三个元素，索引0为简单 1为中等 2为困难
     * solveNumber
     * totalNumber*/
    @GetMapping("/getProblemNumberByDiff/{userId}")
    public Result<List<ProblemNumberVO>>  getProblemNumberByDiff(@PathVariable Long userId){
        return Result.success(problemService.getProblemNumberByDiff(userId));
    }
}
